package com.wk.springboot.retry;

import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

public class RetryStrategyFactory {
    private final Map<String, RetryStrategy> strategies;

    public RetryStrategyFactory(List<RetryStrategy> strategyList) {
        strategies = strategyList.stream()
            .collect(Collectors.toMap(
                s -> s.getClass().getSimpleName().replace("Retry", "").toLowerCase(),
                Function.identity()
            ));
    }

    public RetryStrategy getStrategy(String strategyName) {
        return strategies.getOrDefault(strategyName.toLowerCase(), strategies.get("exponential"));
    }
}